home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 05 Programming / EA2.DOC < prev    next >
Text File  |  2019-04-13  |  24KB  |  700 lines

  1. Documentation for EA - Part Two of Two.
  2.  
  3. EA is an editor-assembler.  Copyright 1984 by Lew Lasher.
  4.  
  5. Overview of assembler features:
  6.  
  7. EA is an assembler for the Commodore 64.  An assembler is a
  8. program used to translate machine language programs from
  9. person-readable form (the source program) to a machine-usable
  10. form (the object program).  The assembler allows you to write,
  11. maintain, and modify a large, complicated machine language
  12. program.
  13.  
  14. Operation:
  15.  
  16. EA requires the source file to be put in one or more text files
  17. on a floppy disk.  After you have created the source files, and
  18. written them to disk (using the C= W command), you can run the 
  19. assembler by typing C= A.
  20.  
  21. EA asks you for the name of the source file.  If you type
  22. "blurfo" for the name, EA first looks for a file named "blurfo".
  23. If it cannot find "blurfo", then it looks for "blurfo.a".  If
  24. it cannot find either one, it prints an error message and returns to the editor.
  25. If it finds either one, it creates an object file called
  26. "blurfo.o".  The filename you type must not be longer than 14
  27. characters, to make room for the extension ".o".
  28.  
  29. Then EA asks you if you want to make a list file.  You should
  30. type "y" or "n".  The list file, which in the current example
  31. would be named "blurfo.l", lists the numeric value of every byte
  32. in the object file, alongside the address at which the byte will
  33. be loaded and the source line corresponding to that byte.  List
  34. files are useful in debugging programs.
  35.  
  36. All these files must be on a disk drive with device number 8
  37. and, if a dual drive, drive number 0.
  38.  
  39. After optionally creating the list file, EA begins the first
  40. pass.  Unless there is an error on the disk drive, you will not
  41. see anything on the screen during the first pass.  No output is
  42. written to either the object file or the optional list file
  43. during the first pass.  The only purpose of the first pass is to
  44. figure out the addresses where the program will be located, and
  45. thereby assign numeric values to each label and symbol in your
  46. program (See below for more about symbols and labels).
  47.  
  48. After the first pass is completed, EA prints the message
  49. "Beginning 2nd pass" and does just that.  During the 2nd pass,
  50. you should see on the screen a listing of your source program,
  51. but with various numbers over in the left margin, and various
  52. error messages preceding the erroneous source lines.  If you
  53. chose to make a list file, the text you see on the screen will
  54. be the text you get in the list file.  Meanwhile the object
  55. program is being written to the object file.
  56.  
  57. Finally you will see the message "Errors detected: 0" which
  58. indicates that EA did not detect any of the errors in your
  59. program.  Note that any errors that EA detects are, in a sense,
  60. "mere warnings", in that (except for I/O errors), you still are
  61. given an object file which can be loaded and run.
  62.  
  63. At any point in either the first or second pass, you may cut off
  64. the assembly by hitting the RUN/STOP key.  You should delete the
  65. incomplete object and list files which will have been created.
  66.  
  67. After EA exits, you can load and run the object file by typing:
  68.  
  69.         load "blurfo.o",8,1
  70.         sys n
  71.  
  72. where n is the address of the start of your program.
  73.  
  74. Miscellaneous specifications:
  75.  
  76. EA will not work with disk drives other than a Commodore 1541 or
  77. an MSD SD-2.  If changes are made to the ROM's in these models,
  78. it may not even work with them.
  79.  
  80. Differences from other assemblers:
  81.  
  82. There are numerous differencs between EA and other assemblers
  83. for the C-64.  Many of these are "added features" of EA which
  84. will not interfere with the assembly of programs written for
  85. another assembler.  The following are the major differences
  86. which must be taken into account to modify a program written for
  87. another assembler:
  88.  
  89. 1.  Every label must be followed by a colon (":").
  90.  
  91. 2.  The directive * = n is not supported.  In other assemblers,
  92. this directive is used primarily for two purposes.  The first
  93. purpose is to establish the address for the first byte in the
  94. object program.  For that purpose, replace:
  95.  
  96.         * = 2049
  97.  
  98. with:
  99.  
  100.         .origin 2049
  101.  
  102. The second common purpose is to allocate an area of memory
  103. without specifing the contents of that memory.  For that
  104. purpose, replace:
  105.  
  106.         * = * + 1
  107.  
  108. with:
  109.  
  110.         .blkb 1
  111.  
  112. 3.  Commodore's assembler has a directive called ".byt" with can
  113. be used to generate both numeric and text data.  In EA, this
  114. directive is called ".byte", and only generates numeric data,
  115. while the .ascii directive generates text data.  Therefore,
  116. replace:
  117.  
  118.         .byt 15, 'Text string', 0
  119.  
  120. with:
  121.  
  122.         .byte 15
  123.         .ascii 'Text string'
  124.         .byte 0
  125.  
  126. 4.  EA lacks the macro directives, conditional assembly
  127. directives, and other specialized directives found in other
  128. assemblers.
  129.  
  130. 5.  EA does not require or allow the ".end" directive which many
  131. assemblers require at the end of a source file.  Actually, EA
  132. ignores the .end as an unrecognized directive, but you should
  133. delete the .end to avoid the error mesage.
  134.  
  135. Format of source file:
  136.  
  137. The source file should be a sequential file, with each line
  138. terminated by a RETURN characater.  Lines are limited to 255
  139. characters, not including the RETURN character.  Blank lines are
  140. legal, and spaces can be put in liberally to improve readability
  141. (exceptions: spaces may not be put in the middle of a numeral or
  142. an identifier).  Upper and lower case letters are treated
  143. identically except in .ascii or .asciz directives and in
  144. character literals.  A semicolon (";") is used to indicate the
  145. beginning of a comment.  All text after the semicolon, and the
  146. semicolon itself, is ignored (exceptions: text strings in .ascii
  147. and .asciz directives and character literals).
  148.  
  149. A valid line can be any of the following:
  150.  
  151. 1.  A blank line.
  152.  
  153. 2.  A symbol definition, e.g.:
  154.  
  155.         cursordown = 17
  156.  
  157. 3.  An instruction for the 6510 microprocesor, e.g.:
  158.  
  159.         lda # 0
  160.  
  161. 4.  An assembler directive, e.g.:
  162.  
  163.         .byte 5
  164.  
  165. 5.  Any of the above (1-4) preceded by one or more labels, e.g.:
  166.  
  167.         start: startloop: lda # 0
  168.         length: .byte 0
  169.         blankline: ; comment
  170.  
  171. Blank lines:
  172.  
  173. Blank lines are useful for the following purposes:  to make the
  174. source or list file more readable, to hold a label, and to hold
  175. comments.  I apologize to people who would not consider a line
  176. having a label and/or a comment to be a "blank line".
  177.  
  178. Symbol definitions:
  179.  
  180. A symbol definition is used to define a name to represent a
  181. numeric value.  One use of symbols is to refer to addresses not
  182. located within the object file, for example, KERNAL routines,
  183. page zero, the special addresses used by the video, sound, and
  184. I/O chips, and vectors:
  185.  
  186.         chrout = 65490
  187.         current.key = 197
  188.         color.memory = $D800
  189.         ADSR1  = 54277
  190.         cia1.data.port.A = $dc00
  191.         irq.vector = 788
  192.  
  193. Symbols can be used for various constants in your program, to
  194. make the program easier to understand and to modify, e.g.:
  195.  
  196.         space.char = 32
  197.         disk.devicenum = 8
  198.         pointer = 251
  199.  
  200. Sometimes you may use a symbol to refer to a memory location
  201. within the object file.  In general, labels are preferred over
  202. symbols for this purpose.  However, note that the following are
  203. very similar in effect:
  204.  
  205.         location:       ; label
  206.         location = *    ; symbol
  207.  
  208. The difference is that a symbol can be redefined many times
  209. within the program without error, while a label is supposed to
  210. refer to only one location.  The one instance in which it makes
  211. sense to use a symbol is to mark the beginning of a loop:
  212.  
  213.         loop = *
  214.             ; body of loop
  215.             dex
  216.             bne loop
  217.  
  218. Since the assembler uses the most recently-assigned value of the
  219. symbol, this pattern can be used for many loops, without having
  220. to think of distinct names for the start of each loop.  But note
  221. that this pattern will fail miserably for a forward branch, or
  222. for a loop within a loop.
  223.  
  224. Because the first pass of the assembler is devoted to defining
  225. labels and symbols, you can refer to a symbol or label that is
  226. defined later in the source file.  This is called a "forward
  227. reference".  More precisely, you are allowed one level of
  228. forward reference.  For example:
  229.  
  230.         a = b + 40
  231.         b = 1024
  232.  
  233. is legal, but:
  234.  
  235.         a = b
  236.         b = c
  237.         c = 100
  238.  
  239. is not legal.  You should not, however, use even a single-level
  240. forward reference in a .blkb or .blkw directive.  (These
  241. directives are described below).  The assembler uses these
  242. directives in the first pass to figure out how much memory to
  243. allocate.  If a symbol used in a .blkb or .blkw directive is
  244. undefined on the first pass, then all subsequent labels will be
  245. defined incorrectly.  Symbols that refer to page zero should be
  246. defined before they are used.  Since instructions referring to
  247. page zero usually take 2 bytes, as opposed to 3 bytes for
  248. addresses on any other page, the assembler needs to know during
  249. the first pass whether an instruction refers to page zero or
  250. not.  If the address is specified by an undefined symbol, the
  251. assembler assumes that the address is NOT on page zero.  If this
  252. assumption proves incorrect, all subsequently-defined labels
  253. will be defined incorrectly.  Therefore, all symbols referring
  254. to page zero MUST be defined before the instructions that refer
  255. to the symbols.
  256.  
  257. Since it is an error to redefine a label, it is also an error to
  258. define a symbol with the same name as a label.
  259.  
  260. Identifiers:
  261.  
  262. An "identifier" is the name used for a symbol or label.  An
  263. identifier must start with a letter, and can have letters,
  264. numeric digits, or periods for subsequent characters.  The
  265. length of an identifier is not limited other than by the maximum
  266. length (255 characters) of a source line.  Upper and lower case
  267. letters are treated identically in identifiers.  The names A, X,
  268. and Y should not be used, even though legal, because other
  269. assemblers forbid their use.  This assembler allows their use,
  270. except that a lone A as an operand to a 6510 instruction will be
  271. confused for a reference to the 6510's accumulater.
  272.  
  273. Examples of legal identifiers:     and illegal identifiers:
  274.  
  275.             Q                       8
  276.             A3333333                3AAAAAAA
  277.             a.b.c                   .a.b.c
  278.  
  279. Machine instructions:
  280.  
  281. (After all, the whole point of an assembler is to let you enter
  282. machine instructions.)  EA recognizes the standard 56
  283. instruction mnemonics, which you may type in either upper or
  284. lower case.  EA uses the standard punctuation for the various
  285. addressing modes:
  286.  
  287.         clc         ; implied
  288.         adc # 1     ; immediate
  289.         asl A       ; accumulator
  290.         ldx Z       ; zero page
  291.         ora Z,X     ; zero page, X
  292.         and Z,Y     ; zero page, Y
  293.         cpx E       ; absolute
  294.         ldy E,X     ; absolute, X
  295.         ldx E,Y     ; absolute, Y
  296.         beq E       ; relative
  297.         eor (Z,X)   ; (indirect,X)
  298.         sbc (Z),Y   ; (indirect),Y
  299.         jmp (Z)     ; absolute indirect
  300.  
  301. where Z is an expression whose value is between 0-255, and E is
  302. an expression whose value is not necessarily between 0-255. 
  303. (The exact definition of an "expression" will be given later.) 
  304. Note that it is often not the punctuation, but the value of the
  305. expression, which distinguishes certain addressing modes.
  306.  
  307. You may, but need not, put in spaces before or after a "(", ")",
  308. ",", or "#".  You must put in a space after the name of the
  309. instruction if the operand starts with a letter.
  310.  
  311. Expressions:
  312.  
  313. An expression is a bunch of text that represents a numeric
  314. value.  The following are legal expressions:
  315.  
  316. 1.  A decimal numeral (0 to 65535):
  317.  
  318.         1024
  319.  
  320. 2.  A hexadecimal numeral, preceded by a dollar sign:
  321.  
  322.         $ff
  323.         $DC00
  324.  
  325. 3.  A binary numeral, preceded by a percent sign:
  326.  
  327.         %10000001
  328.  
  329. 4.  A character literal, preceded by an apostrophe:
  330.  
  331.         'A
  332.  
  333. 5.  An identifier:
  334.  
  335.         loop
  336.         color.memory
  337.         disk.devicenum
  338.  
  339.     The numeric value of an identifier is given by its most
  340.     recent definition as a symbol or as a label.
  341.  
  342. 6.  The "location counter", either a period or asterisk:
  343.  
  344.         .
  345.         *
  346.  
  347.     The numeric value of the location counter is the address in
  348.     the object program corresponding to the beginning of the
  349.     current source line.
  350.  
  351. 7.  An expression preceded by a "unary operator":
  352.  
  353.         < E         ; low-order byte of E
  354.         > E         ; high-order byte of E
  355.         - E         ; negative E (two's complement)
  356.         ? E         ; logical (one's) complement of E
  357.  
  358. 8.  An expression followed by a "binary operator" followed by a
  359. second expression:
  360.  
  361.         E1 + E2     ; addition
  362.         E1 - E2     ; subtraction
  363.         E1 * E2     ; multiplication
  364.         E1 / E2     ; integer division
  365.         E1 % E2     ; modulo (remainder after integer division)
  366.         E1 & E2     ; logical AND
  367.         E1 ! E2     ; logical OR
  368.         E1 ^ E2     ; arithmetic shift
  369.                     ; left shift if E2 is positive
  370.                     ; right shift if E2 is negative
  371.  
  372. If more than one operator is used in the same expression, they
  373. are done in the following order: ? - (negative) * % / -
  374. (subtraction) + & ! ^ < >.  If the same operator appears twice,
  375. evaluation is from right to left.  You can override the normal
  376. order of evaluation by using brackets ("[" and "]") as
  377. parentheses.
  378.  
  379. Note, however, that all these arithmetic operations may be done
  380. only on constant expressions.  That is, you cannot use the above
  381. operators to add the contents of various memory locations.  The
  382. usefulness of elaborate assembler expressions is primarily to
  383. define one symbol in terms of another, so that if you change one
  384. symbol, various other symbols are automatically redefined.
  385.  
  386. Assembler directives:
  387.  
  388. The assembler directives perform various miscellaneous functions:
  389.  
  390. .byte
  391. .byte Z
  392. .byte Z1, Z2, ... , Z3
  393.  
  394.     The .byte directive allocates one or more bytes in the
  395.     object file.  If an expression is given, the expression is
  396.     put in as the initial value of the byte.  If more than one
  397.     expression is given, separated by commas, than a byte is
  398.     allocated for each expression.  If no expression is given, a
  399.     single byte is allocated with an initial value of zero.  Only
  400.     the low-order byte of the expression is used.
  401.  
  402. .word
  403. .word E
  404. .word E1, E2, ... , E3
  405.  
  406.     The .word directive is very similar to the .byte directive,
  407.     but two bytes are allocated for each expression, the first
  408.     for the low-order byte and the second for the high-order
  409.     byte.  If no expression is given, then two bytes are
  410.     allocated, both initialized to zero.
  411.  
  412.     Note that
  413.  
  414.             .word E
  415.  
  416.     is exactly equivalent to:
  417.  
  418.             .byte < E, > E
  419.  
  420. .blkb
  421. .blkb E
  422.  
  423.     The .blkb directive is used to allocate memory in the object
  424.     program without specifying the initial values.  If an
  425.     expression is given, that number of bytes is allocated.  If
  426.     no expression is given, 1 byte is allocated.  But if the
  427.     value of the expression is zero, no bytes are allocated.  If
  428.     the expression is negative or greater than 32767, an error
  429.     message is generated and no bytes are allocated.
  430.  
  431. .blkw
  432. .blkw E
  433.  
  434.     The .blkw directive is similar to the .blkb directive,
  435.     except that the number of bytes to be allocated is
  436.     multiplied by two.
  437.  
  438. .ascii "Text string"
  439.  
  440.     The .ascii directive is used to allocate memory in the
  441.     object program for a text string.  One byte is allocated for
  442.     each character in the text string, and each byte is
  443.     initialized with the character code (not the code for screen
  444.     memory) for the character from the source line.  The text
  445.     string can be delimited by any character not found within
  446.     the text string, with the exception that a semicolon (";"),
  447.     a space, or a RETURN character may not be used as the
  448.     delimiter.  Note that the character codes are not true ASCII
  449.     but the Commodore variant, sometimes called PETSCII.
  450.  
  451. .asciz /Text string/
  452.  
  453.     The .asciz directive is similar to the .ascii directive,
  454.     except that a zero byte is allocated after the text string.
  455.  
  456. .origin E
  457.  
  458.     The .origin directive is used at the beginning of the source
  459.     file to specify the address to be used for the first byte in
  460.     the object file.  In fact, the .origin directive need not be
  461.     literally on the first line of the source file, but it must
  462.     come before any source lines that allocate memory in the
  463.     object file.  If you do not include a .origin directive, the
  464.     default origin is 49152 ($C000 hexadecimal).
  465.  
  466. .print E text
  467.  
  468.     The .print directive is used to print messages on the
  469.     terminal and into the optional list file.  The expression
  470.     following the .print is evaluated.  The numeric value of
  471.     that expression is printed, in decimal, to the screen and
  472.     into the optional list file, followed by any other text on
  473.     the source line.  The main use of the .print directive is to
  474.     produce a memory map rather than a full listing of every
  475.     line of the program.  The output from the .print directive
  476.     is performed even if the .nolist directive is in effect. 
  477.  
  478.     Examples:
  479.  
  480.             .print subroutine subroutine
  481.             subroutine: 
  482.                 ...
  483.                 ...
  484.                 rts
  485.  
  486.             .print * - subroutine, length of subroutine
  487.  
  488.             .print * End of file
  489.             .print * - start, Size of file
  490.  
  491. .nolist
  492.  
  493.     The .nolist directive turns off the listing of every source
  494.     line to the screen and to the optional list file.  The
  495.     output of the .print directive is still performed, however.
  496.  
  497. .list
  498.  
  499.     The .list directive turns back on the listing of every
  500.     source line, after a previous .nolist directive.  In this
  501.     way, you can make a list file of only those particular
  502.     routines which you are interested in debugging.
  503.  
  504. .include identifier
  505.  
  506.     The .include directive is used to incorporate another source
  507.     file as though it had been merged with the principal source
  508.     file.  This allows you to have a library of common
  509.     subroutines without having to make a separate copy of the
  510.     subroutines in each program in which you use them.  It is
  511.     also useful to make several, slightly different versions of
  512.     the same program.  It is also useful to divide up a large
  513.     program for more convenient editing.  It is also useful for
  514.     incorporating a list of common symbol definitions, such as
  515.     the addresses of the KERNAL routines.  The assembler first
  516.     looks for a file whose name is given by the identifier
  517.     (converted to lower case).  If that file cannot be found, it
  518.     adds ".a" to the filename and looks for that name.  After
  519.     the assembler has finished processing the included source
  520.     file, it returns to the principal source file and continues
  521.     from the line following the .include directive.  The
  522.     included file can include a "third-level" source file, but
  523.     there is a maximum of four levels of inclusion.
  524.  
  525. Error messages:
  526.  
  527. File name may be 1 to 14 chars long
  528.  
  529.     If, when the assembler initially asks for the name of the
  530.     source file, you hit the RETURN key with no name, or give a
  531.     name longer than 14 characters, you get this message.
  532.  
  533. Couldn't create object file:
  534. Couldn't create list file:
  535. Error reading source file:
  536. Error writing to list file:
  537. Error writing to list file:
  538. Error closing object file:
  539. Error closing list file:
  540. Error re-reading source file
  541.  
  542.     Also prints the error message given by the disk drive
  543.  
  544. Couldn't open control or random channel
  545.  
  546.     May indicate that you ran EA while file channels were still
  547.     opened from another program.
  548.  
  549. Line too long
  550.  
  551.     Source line longer than 255 characters.
  552.  
  553. Assembly terminated by STOP key
  554.  
  555. Unrecognized statement
  556.  
  557.     The first non-blank character in the source line was neither
  558.     a letter nor a period.  May indicate that the source line
  559.     contains a non-printing character.
  560.  
  561. Unrecognized opcode
  562.  
  563.     May indicate a misspelled opcode, or the accidental omission
  564.     of the colon after a label or of the = following a symbol
  565.     definition.
  566.  
  567. Extra input ignored
  568.  
  569.     May indicate the omission of the semicolon preceding a
  570.     comment.  May also indicate the omission of an operator from
  571.     an expression.
  572.  
  573. No character after '
  574.  
  575.     Indicates that an apostrophe was the last character in the
  576.     source line.
  577.  
  578. Malformed expression
  579.  
  580. Warning - extra [
  581.  
  582. Warning - extra ]
  583.  
  584. Warning - arithmetic overflow
  585.  
  586.     Indicates an arithmetic operation whose result required more
  587.     than 16 bits.
  588.  
  589. Warning - division by zero
  590.  
  591. Internal assembler error
  592.  
  593.     This message indicates that the assembler was not able to
  594.     evaluate an expression properly.
  595.  
  596. Second argument to ^ must be -15 to 15
  597.  
  598. Undefined symbol: identifier
  599.  
  600. Symbol table full
  601.  
  602.     Indicates that the assembler was not able to create a label
  603.     or symbol because of insufficient available memory.
  604.  
  605. Warning - redefining label:
  606.  
  607.     This may indicate that the source file has two different
  608.     labels with the same name, or a symbol and a label with the
  609.     same name.  It also may indicate a duplicate name from an
  610.     include file.  If, however, you get this error message for
  611.     every label in the source file, it means that the value of
  612.     the labels changed from the first pass to the second pass. 
  613.     This, in turn, usually means that a symbol was used in a
  614.     .blkb or .blkw directive before it was defined, or that a
  615.     symbol referring to page zero was used before it was
  616.     defined.
  617.  
  618. Unrecognized addressing mode
  619.  
  620. Improper addressing mode for opcode
  621.  
  622.     Not all the possible addressing modes can be used for any
  623.     particular opcode.  See the C-64 Programmer's Reference
  624.     Manual, or any other book about the 6502, for a description
  625.     of the permissible addressing modes for each opcode.
  626.  
  627. Expression truncated
  628.  
  629.     An expression used with an opcode in immediate mode or used
  630.     in a .byte directive was not within the range -256 to 255.
  631.  
  632. Branch out of range
  633.  
  634.     The various branch instructions for the 6510 may only be
  635.     used to branch to a location less than 254 bytes before the
  636.     branch instruction or less than 253 bytes after the branch
  637.     instruction.  This error message is also often given if the
  638.     expression specifying the address uses an undefined
  639.     identifier.
  640.  
  641. Unrecognized directive
  642.  
  643.     A source line began with a period, but was not one of the
  644.     assembler directives described above.
  645.  
  646. Warning - extra comma
  647.  
  648.     A .byte or .word directive had a trailing comma after the
  649.     last expression.
  650.  
  651. Warning - comma inserted
  652.  
  653.     A .byte or .word directive had two expressions not separated
  654.     by a comma.
  655.  
  656. Argument must be positive
  657.  
  658.     The argument to .blkb or to .blkw was negative, or greater
  659.     than 32767.
  660.  
  661. Missing string
  662.  
  663.     An .ascii or .asciz directive did not have a text string, or
  664.     used a semicolon as the delimiter.
  665.  
  666. Unterminated string
  667.  
  668.     An .ascii or .asciz directive was followed by a text string
  669.     which was not followed by the delimiter character preceding
  670.     the text string.
  671.  
  672. Origin can only be set once at start
  673.  
  674.     The source file contained two .origin directives, or
  675.     contained an .origin directive after a source line which
  676.     allocated memory.  May indicate that an include file had an
  677.     .origin directive.
  678.  
  679. Filename must start with a letter
  680.  
  681.     A .include directive was not followed by an identifier.
  682.  
  683. Already at maximum depth of includes
  684.  
  685.     Only four levels of source files are allowed.
  686.  
  687. Couldn't open include file:
  688.  
  689.     Prints the error message from the disk drive
  690.  
  691. File number not opened
  692. File number out of range
  693. File number already in use
  694. Directory not updated
  695.  
  696.     These messages indicate internal errors in the file-handling
  697.     routines used by the assembler.
  698.  
  699. For more information, call Lew Lasher at (617) 547-0340
  700.